//
//  UIViewController+CYViewController.m
//  cyjf
//
//  Created by tauCross on 2017/6/4.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "UIViewController+CYViewController.h"

#import <UMMobClick/MobClick.h>



@implementation UIViewController (CYViewController)

+ (void)load
{
    {
        Method oriMethod = class_getInstanceMethod(self, @selector(viewWillAppear:));
        Method cyMethod = class_getInstanceMethod(self, @selector(cy_viewWillAppear:));
        method_exchangeImplementations(oriMethod, cyMethod);
    }
    {
        Method oriMethod = class_getInstanceMethod(self, @selector(viewWillDisappear:));
        Method cyMethod = class_getInstanceMethod(self, @selector(cy_viewWillDisappear:));
        method_exchangeImplementations(oriMethod, cyMethod);
    }
}

- (void)cy_viewWillAppear:(BOOL)animated
{
    [self cy_viewWillAppear:animated];
    NSArray *ext = @[@"UICompatibilityInputViewController",
                     @"UINavigationController",
                     @"UITabBarController",
                     @"UIAlertController",
                     @"UIInputWindowController"];
    BOOL flag = YES;
    for(NSString *classString in ext)
    {
        Class class = NSClassFromString(classString);
        if(class)
        {
            if([self isKindOfClass:class])
            {
                flag = NO;
                break;
            }
        }
    }
    if(flag)
    {
        [MobClick beginLogPageView:NSStringFromClass([self class])];
    }
}

- (void)cy_viewWillDisappear:(BOOL)animated
{
    [self cy_viewWillDisappear:animated];
    NSArray *ext = @[@"UICompatibilityInputViewController",
                     @"UINavigationController",
                     @"UITabBarController",
                     @"UIAlertController",
                     @"UIInputWindowController"];
    BOOL flag = YES;
    for(NSString *classString in ext)
    {
        Class class = NSClassFromString(classString);
        if(class)
        {
            if([self isKindOfClass:class])
            {
                flag = NO;
                break;
            }
        }
    }
    if(flag)
    {
        [MobClick endLogPageView:NSStringFromClass([self class])];
    }
}

@end
